package member

import (
	"context"
	"errors"
	"group-buy/group_buy/internal/models"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetRealNameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRealNameLogic {
	return &GetRealNameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetRealNameLogic) GetRealName(req *types.GetRealNameReq) (resp *types.UserInfo, err error) {
	m := &models.LsUserInfo{UserId: req.UserId}
	get, err := l.svcCtx.Engine.Get(m)
	if err != nil {
		return nil, err
	}
	if !get {
		return nil, errors.New("当前用户未完成实名认证")
	}

	return &types.UserInfo{
		Id:               m.Id,
		UserId:           m.UserId,
		ChannelUser:      m.ChannelUser,
		CertType:         m.CertNo,
		Name:             m.Name,
		CertNo:           m.CertNo,
		CertValidityType: m.CertValidityType,
		CertBeginDate:    m.CertBeginDate,
		CertEndDate:      m.CertEndDate,
		MobileNo:         m.MobileNo,
		Email:            m.Email,
	}, nil
}
